//
//  BBApplyTypeViewController.m
//  BearSiX
//
//  Created by BearBaby on 16/3/26.
//  Copyright © 2016年 Tom. All rights reserved.
//

#import "BBApplyTypeViewController.h"
#import "BBSixHeader.h"
#import "BBApplyTypeCollectionViewCell.h"
#import "BBLeaveViewController.h"
#import "BBOvertimeViewController.h"
#import "BBBusinessTravelController.h"
#import "BBLegworkViewController.h"
#import "BBCustomViewController.h"
//
#import "BBReimbursementViewController.h"
#import "BBBuyViewController.h"
@interface BBApplyTypeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>{
    NSArray* textArray;
    NSArray* images;
}
@property(nonatomic,strong)UICollectionView* collectionView;

@end

@implementation BBApplyTypeViewController
-(UICollectionView *)collectionView{
    
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.minimumInteritemSpacing = 2;
        flowLayout.minimumLineSpacing = 2;
        [flowLayout setItemSize:CGSizeMake((WINSIZEWIDTH-2)/2, (WINSIZEWIDTH-2*3)/8*3)];
        [flowLayout setSectionInset:UIEdgeInsetsMake(0, 0, 0, 0)];
        //   [flowLayout setHeaderReferenceSize:CGSizeMake(WINSIZEWIDTH, WINSIZEWIDTH/1.5)];
        [flowLayout setScrollDirection:(UICollectionViewScrollDirectionVertical)];
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH, WINSIZEHEIGHT) collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = [UIColor colorWithHexString:@"f2f1fc"];
        _collectionView.delegate = self;
        _collectionView.dataSource =self;
    }
    return _collectionView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"选择申请类型";
    textArray = @[@"请假申请",@"加班申请",@"出差申请",@"外勤申请",@"报销申请",@"采购申请"];
    images = @[@"menshi_y",@"dingdan_y",@"sheying_y",@"yuyue_y",@"lifu_y",@"huazhuang_y"];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"自定义" style:UIBarButtonItemStylePlain target:self action:@selector(custom:)];
    
    [self.collectionView registerClass:[BBApplyTypeCollectionViewCell class] forCellWithReuseIdentifier:@"founctionCell"];
    [self.view addSubview:self.collectionView];
}
//-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
//    
//    if (section==0) {
//        return CGSizeMake(WINSIZEWIDTH, WINSIZEWIDTH/1.26);
//    }else{
//        return CGSizeMake(WINSIZEWIDTH, WINSIZEWIDTH/5);
//    }
//}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    

    return 6;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    BBApplyTypeCollectionViewCell *cell = (BBApplyTypeCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"founctionCell" forIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:images[indexPath.row]];
    cell.itemLabel.text = [textArray objectAtIndex:indexPath.row];
    
    return cell;
}
#pragma mark -- collection dianji
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    BBLeaveViewController* leaveVC = [BBLeaveViewController new];
    BBOvertimeViewController* overtimeVC = [BBOvertimeViewController new];
    BBBusinessTravelController* businessVC = [BBBusinessTravelController new];
    BBLegworkViewController* legVC = [[BBLegworkViewController alloc]init];
    BBReimbursementViewController* reimburesment = [BBReimbursementViewController new];
    BBBuyViewController* buyVC = [BBBuyViewController new];
        switch (indexPath.row) {
            case 0:
                [self.navigationController pushViewController:leaveVC animated:YES];
                break;
            case 1:
                [self.navigationController pushViewController:overtimeVC animated:YES];
                break;
            case 2:
                [self.navigationController pushViewController:businessVC animated:YES];
                break;
            case 3:
                [self.navigationController pushViewController:legVC animated:YES];
                break;
            case 4:
                [self.navigationController pushViewController:reimburesment animated:YES];
                break;
            case 5:
                [self.navigationController pushViewController:buyVC animated:YES];
                break;
                
            default:
                break;
        }
    
}
//自定义
-(void)custom:(UIBarButtonItem*)item{
    BBCustomViewController* customVC = [BBCustomViewController new];
    [self.navigationController pushViewController:customVC animated:YES];

}
@end
